package com.ruoyi.ldzlsb.service.impl;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ldzlsb.mapper.SbMaintenanceRecordMapper;
import com.ruoyi.ldzlsb.domain.SbMaintenanceRecord;
import com.ruoyi.ldzlsb.service.ISbMaintenanceRecordService;

/**
 * 保养单Service业务层处理
 * 
 * @author anli
 * @date 2025-01-11
 */
@Service
public class SbMaintenanceRecordServiceImpl implements ISbMaintenanceRecordService 
{
    @Autowired
    private SbMaintenanceRecordMapper sbMaintenanceRecordMapper;

    /**
     * 查询保养单
     * 
     * @param recordId 保养单主键
     * @return 保养单
     */
    @Override
    public SbMaintenanceRecord selectSbMaintenanceRecordByRecordId(Long recordId)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordByRecordId(recordId);
    }

    /**
     * 查询保养单列表
     * 
     * @param sbMaintenanceRecord 保养单
     * @return 保养单
     */
    @Override
    public List<SbMaintenanceRecord> selectSbMaintenanceRecordList(SbMaintenanceRecord sbMaintenanceRecord)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordList(sbMaintenanceRecord);
    }

    /**
     * 查询保养单列表（包含关联信息）
     * 
     * @param sbMaintenanceRecord 保养单
     * @return 保养单集合
     */
    @Override
    public List<SbMaintenanceRecord> selectSbMaintenanceRecordWithInfoList(SbMaintenanceRecord sbMaintenanceRecord)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordWithInfoList(sbMaintenanceRecord);
    }

    /**
     * 新增保养单
     * 
     * @param sbMaintenanceRecord 保养单
     * @return 结果
     */
    @Override
    public int insertSbMaintenanceRecord(SbMaintenanceRecord sbMaintenanceRecord)
    {
        sbMaintenanceRecord.setCreateTime(new Date());
        if (sbMaintenanceRecord.getIsDelete() == null)
        {
            sbMaintenanceRecord.setIsDelete("0");
        }
        if (sbMaintenanceRecord.getMaintenanceStatus() == null)
        {
            sbMaintenanceRecord.setMaintenanceStatus("0");
        }
        if (sbMaintenanceRecord.getMaintenanceResult() == null)
        {
            sbMaintenanceRecord.setMaintenanceResult("2");
        }
        return sbMaintenanceRecordMapper.insertSbMaintenanceRecord(sbMaintenanceRecord);
    }

    /**
     * 修改保养单
     * 
     * @param sbMaintenanceRecord 保养单
     * @return 结果
     */
    @Override
    public int updateSbMaintenanceRecord(SbMaintenanceRecord sbMaintenanceRecord)
    {
        sbMaintenanceRecord.setUpdateTime(new Date());
        return sbMaintenanceRecordMapper.updateSbMaintenanceRecord(sbMaintenanceRecord);
    }

    /**
     * 批量删除保养单
     * 
     * @param recordIds 需要删除的保养单主键
     * @return 结果
     */
    @Override
    public int deleteSbMaintenanceRecordByRecordIds(Long[] recordIds)
    {
        return sbMaintenanceRecordMapper.deleteSbMaintenanceRecordByRecordIds(recordIds);
    }

    /**
     * 删除保养单信息
     * 
     * @param recordId 保养单主键
     * @return 结果
     */
    @Override
    public int deleteSbMaintenanceRecordByRecordId(Long recordId)
    {
        return sbMaintenanceRecordMapper.deleteSbMaintenanceRecordByRecordId(recordId);
    }

    /**
     * 根据保养单编号查询保养单
     * 
     * @param recordCode 保养单编号
     * @return 保养单
     */
    @Override
    public SbMaintenanceRecord selectSbMaintenanceRecordByRecordCode(String recordCode)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordByRecordCode(recordCode);
    }

    /**
     * 根据保养计划ID查询保养单列表
     * 
     * @param planId 保养计划ID
     * @return 保养单列表
     */
    @Override
    public List<SbMaintenanceRecord> selectSbMaintenanceRecordByPlanId(Long planId)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordByPlanId(planId);
    }

    /**
     * 根据设备ID查询保养单列表
     * 
     * @param equipmentId 设备ID
     * @return 保养单列表
     */
    @Override
    public List<SbMaintenanceRecord> selectSbMaintenanceRecordByEquipmentId(Long equipmentId)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordByEquipmentId(equipmentId);
    }

    /**
     * 根据保养人员ID查询保养单列表
     * 
     * @param maintainerId 保养人员ID
     * @return 保养单列表
     */
    @Override
    public List<SbMaintenanceRecord> selectSbMaintenanceRecordByMaintainerId(Long maintainerId)
    {
        return sbMaintenanceRecordMapper.selectSbMaintenanceRecordByMaintainerId(maintainerId);
    }

    /**
     * 统计今日保养单数量
     * 
     * @return 今日保养单数量
     */
    @Override
    public int countTodayMaintenanceRecords()
    {
        return sbMaintenanceRecordMapper.countTodayMaintenanceRecords();
    }
} 